/*Copyright (C) 2013-2022 LZE*/
#include<bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N = 1000010;
ll T,n,m;
ll a[N] = {0},b[N] = {0};
int main(){
    scanf("%lld",&n);
    for(ll i = 1;i <= n;i++)scanf("%lld",&a[i]);
    ll p,lp,rp,limit = 1;
    for(ll i = 1;limit < n;i++)limit = limit * 2;
    ll bot = limit - n + 1;
    for(ll i = n + 1;i <= limit;i++)a[i] = -INF;
    for(ll step = 1;step <= limit;step = step * 2){
        for(ll i = 1;i <= limit;i = i + step){
            p = 1,lp = i,rp = i + step / 2;
            for(ll j = 1;j <= step;j++,p++){
                if(lp == i + step / 2){ b[p] = a[rp]; rp++; }
                else if(rp == i + step){ b[p] = a[lp]; lp++; }
                else if(a[lp] <= a[rp]){ b[p] = a[lp]; lp++; }
                else if(a[lp] > a[rp]){ b[p] = a[rp]; rp++; }
            }
            for(ll j = i,k = 1;k < p;j++,k++)a[j] = b[k];
        }
    }
    for(ll i = bot;i < n + bot;i++)printf("%lld ",a[i]);
    printf("\n");
    return 0;
}
